package com.smart_campus.campus.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.smart_campus.bus.domain.Journal;
import com.smart_campus.bus.vo.JournalVo;
import com.smart_campus.campus.vo.CampusCarouselVo;
import com.smart_campus.campus.vo.NewSchoolVo;
import com.smart_campus.sys.common.DataGridView;
import org.junit.platform.commons.util.PackageUtils;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import com.smart_campus.campus.mapper.NewsSchoolMapper;
import com.smart_campus.campus.domain.NewsSchool;
import com.smart_campus.campus.service.NewsSchoolService;

import java.util.List;

@Service
public class NewsSchoolServiceImpl implements NewsSchoolService{

    @Resource
    private NewsSchoolMapper newsSchoolMapper;

    //@CacheEvict 删除的注解通过对象id在redis中删除数据
//    @CacheEvict(cacheNames = "com.smart_campus.campus.service.impl.NewsSchoolServiceImpl",key = "#articleid")
    @Override
    public int deleteByPrimaryKey(Integer articleid) {
        return newsSchoolMapper.deleteByPrimaryKey(articleid);
    }

    //@CachePut 要返回对象 添加通过reids主键回填的id来在redis创建对应id的对象数据
//    @CachePut(cacheNames = "com.smart_campus.campus.service.impl.NewsSchoolServiceImpl",key = "#result.articleid")
    @Override
    public NewsSchool insert(NewsSchool record) {
        newsSchoolMapper.insert(record);
        return record;
    }

    @Override
    public  int tup(NewsSchool record){
        return newsSchoolMapper.tup(record);
    }

    //@CachePut 要返回对象 添加通过reids主键回填的id来在redis创建对应id的对象数据
//    @CachePut(cacheNames = "com.smart_campus.campus.service.impl.NewsSchoolServiceImpl",key = "#result.articleid")
    @Override
    public NewsSchool insertSelective(NewsSchool record) {
        newsSchoolMapper.insertSelective(record);
        return record;
    }

    //@Cacheable 返回对象 通过对象id在redis中创建对象保存,方便下次使用
//    @Cacheable(cacheNames ="com.smart_campus.campus.service.impl.NewsSchoolServiceImpl",key = "#articleid")
    @Override
    public NewsSchool selectByPrimaryKey(Integer articleid) {
        return newsSchoolMapper.selectByPrimaryKey(articleid);
    }

    @Override
    public int updateByPrimaryKeySelective(NewsSchool record) {
        return newsSchoolMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(NewsSchool record) {
        return newsSchoolMapper.updateByPrimaryKey(record);
    }

    @Override
    public DataGridView queryCarousel(NewSchoolVo newSchoolVo) {
        Page<Object> page = PageHelper.startPage(newSchoolVo.getPage(),newSchoolVo.getLimit());
        List<NewSchoolVo> list = newsSchoolMapper.queryCarousel(newSchoolVo);
        return new DataGridView(page.getTotal(),list);
    }

    @Override
    public List<Journal> getHotNews() {
        return null;
    }

    @Override
    public DataGridView selh(NewSchoolVo newSchoolVo) {
        Page<Object> page = PageHelper.startPage(newSchoolVo.getPage(),newSchoolVo.getLimit());
        List<NewSchoolVo> list = newsSchoolMapper.selh(newSchoolVo);
        return new DataGridView(page.getTotal(),list);
    }



}
